/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/********************************************************************************************************
 * \file     Mcal_SectionCopy.c                                                                         *
 * \brief    AUTOSAR 4.3.1 MCAL McalLib Driver                                                          *
 *                                                                                                      *
 * <table>                                                                                              *
 * <tr><th>Date           <th>Version                                                                   *
 * <tr><td>2025/01/06     <td>1.0.0                                                                     *
 * </table>                                                                                             *
 *******************************************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/********************************************************************************************************
 *                                      Include header files                                            *
 *******************************************************************************************************/
#include "Mcal_Soc.h"
#include "Part.h"
#include "Mcal.h"
#include "Mcal_Fault.h"
/********************************************************************************************************
 *                                  Global Function Declarations                                        *
 *******************************************************************************************************/
#define MCALLIB_START_SEC_CODE
#include "McalLib_MemMap.h"
/** *****************************************************************************************************
 * \brief This function remap CPU addr to DMA addr.
 *
 * \verbatim
 * Syntax             : Mcal_AddressConvert
 *
 * Service ID[hex]    : 0x00
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : Reentrant
 *
 * Parameters (in)    : cpu_addr - Pointer to cpu address
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : transfer cpu addr to dma addr
 * \endverbatim
 * Traceability       : SWSR SWSR_LIB_013
 *******************************************************************************************************/
uint32 Mcal_AddressConvert(uint32 cpuAddr)
{
    uint32 tcmBaseAddr;
    uint32 tcmAddrsize;
    uint32 convertAddr = cpuAddr;
    uint8 coreId = Mcal_GetCpuIndex();

    MCALLIBHook_Mcal_AddressConvert();

    if (CPU_INDEX_0 == coreId)
    {
        tcmBaseAddr = CORE0_TCMA_BASE;
        tcmAddrsize = CORE0_TCMA_SIZE;
    }
    else if (CPU_INDEX_1 == coreId)
    {
        tcmBaseAddr = CORE1_TCMA_BASE;
        tcmAddrsize = CORE1_TCMA_SIZE;
    }
    else if (CPU_INDEX_2 == coreId)
    {
        tcmBaseAddr = CORE2_TCMA_BASE;
        tcmAddrsize = CORE2_TCMA_SIZE;
    }
    else if (CPU_INDEX_3 == coreId)
    {
        tcmBaseAddr = CORE3_TCMA_BASE;
        tcmAddrsize = CORE3_TCMA_SIZE;
    }
    else
    {
        /* PRQA S 2983 2 */
        tcmAddrsize = 0;
        tcmBaseAddr = 0;
    }

    if (cpuAddr < tcmAddrsize)
    {
        convertAddr = cpuAddr + tcmBaseAddr;
    }

    return convertAddr;
}

#define MCALLIB_STOP_SEC_CODE
#include "McalLib_MemMap.h"
#ifdef __cplusplus
}
#endif
/* End of file */
